
#### Women Want an Answer! Field Experiments on Elected Officials and Gender Bias

## Gabriele Magni and Zoila Ponce de Leon

## JEPS 2020

##################################


# Load libraries

library(lme4)
library(stargazer)
 

# Read and attach data

MPs.replies <- read.csv("C:/Users/gmagni/OneDrive/SideProjects/1-Zoi/0000-JEPS/Dataset/merged-updated-Rnames-dates-final-jeps.csv")
attach(MPs.replies)



## Code variables 


#Re-code treatment: Name: "treat.female":  female sender = 1; male sender = 0
table(treat)
treat.female <- as.numeric(treat=="F")
table(treat.female)

table(MPs.replies$treat)
treat.female <- as.numeric(MPs.replies$treat=="F")
table(treat.female)
MPs.replies$treat.female <- treat.female


table(treat)
treat.female <- as.numeric(treat=="F")
table(treat.female)

#Recode age (which is a factor) into a numeric variable
age2 <- as.character(age)
age2 <- as.numeric(age2)
table(age2)
MPs.replies$age2 <- age2


#Recode ideology (which is a factor) into a numeric variable
party.gen.ideo2 <- as.character(party.gen.ideo)
party.gen.ideo2 <- as.numeric(party.gen.ideo2)
table(party.gen.ideo2)
MPs.replies$party.gen.ideo2 <- party.gen.ideo2


#Recode economic ideology (which is a factor) into a numeric variable
table(party.eco.ideo)
party.eco.ideo2 <- as.character(party.eco.ideo)
party.eco.ideo2 <- as.numeric(party.eco.ideo2)
table(party.eco.ideo2)

#Recode social ideology (which is a factor) into a numeric variable
table(party.soc.ideo)
party.soc.ideo2 <- as.character(party.soc.ideo)
party.soc.ideo2 <- as.numeric(party.soc.ideo2)
table(party.soc.ideo2)

#Create country dummies
table(country)
ireland <- as.numeric(country=="Ireland")
italy <- as.numeric(country=="Italy")
france <- as.numeric(country=="France")
germany <- as.numeric(country=="Germany")
netherlands <- as.numeric(country=="Netherlands")
argentina <- as.numeric(country=="Argentina")
brazil <- as.numeric(country=="Brazil")
chile <- as.numeric(country=="Chile")
colombia <- as.numeric(country=="Colombia")
mexico <- as.numeric(country=="Mexico")
uruguay <- as.numeric(country=="Uruguay")




##############
## ANALYSIS ##
##############


# APPENDIX: TABLE A1
# Experimental Balance 
# Verify balance b/w MPs who received email from female alias and MPs who received email from male alias

library(plyr)
ddply(MPs.replies, .(treat), summarize,  MP.Gender=mean(female, na.rm=TRUE))
ddply(MPs.replies, .(treat), summarize,  MP.Age=mean(age2, na.rm=TRUE))
ddply(MPs.replies, .(treat), summarize,  Party.Ideol=mean(party.gen.ideo2, na.rm=TRUE))
ddply(MPs.replies, .(treat), summarize,  Gov.Coal=mean(gov.coal, na.rm=TRUE))
ddply(MPs.replies, .(treat), summarize,  ES.Proport=mean(es.proport, na.rm=TRUE))
ddply(MPs.replies, .(treat), summarize,  Share.Female.MPs=mean(female.mps, na.rm=TRUE))




# APPENDIX: TABLE A4

# MPs' responsiveness to citizens' demands ("real responses," all countries)
# Multilevel (random intercept)

multil.treat <- glmer(real.resp.1 ~ treat.female + (1 | country), 
                        family=binomial(link="logit"), data=MPs.replies)
summary(multil.treat)


multil.general <- glmer(real.resp.1 ~ treat.female + female + age2 + (1 | country), 
                      family=binomial(link="logit"), data=MPs.replies)
summary(multil.general)


multi.all.dates <- glmer(real.resp.1 ~ treat.female + female + age2 + party.gen.ideo2 + gov.coal +
                           es.prefer + female.mps + post.days +
                           (1| country), 
                         family=binomial(link="logit"), data=MPs.replies)
summary(multi.all.dates)

stargazer(multil.treat, multil.general, multi.all.dates, type="html", digits = 2,
          star.char = c("*", "**", "***"), 
          star.cutoffs = c(0.05, 0.01, 0.001), 
          notes        = "*p<0.05; **p<0.01; ***p<0.001", 
          notes.append = FALSE, no.space = TRUE,
          out="mod.htm")



# APPENDIX TABLE A5

# MPs' responsiveness to citizens' demands (all responses, all countries)
# Multilevel (random intercept)

multil.treat.allresp <- glmer(resp.1 ~ treat.female + (1 | country), 
                              family=binomial(link="logit"), data=MPs.replies)
summary(multil.treat.allresp)


multil.general.allresp <- glmer(resp.1 ~ treat.female + female + age2 + (1 | country), 
                                family=binomial(link="logit"), data=MPs.replies)
summary(multil.general.allresp)


multi.all.dates.allresp <- glmer(resp.1 ~ treat.female + female + age2 + party.gen.ideo2 + gov.coal +
                                   es.prefer + female.mps + post.days +
                                   (1| country), 
                                 family=binomial(link="logit"), data=MPs.replies)
summary(multi.all.dates.allresp)


stargazer(multil.treat.allresp, multil.general.allresp, multi.all.dates.allresp, 
          type="html", digits = 2,
          star.char = c("*", "**", "***"), 
          star.cutoffs = c(0.05, 0.01, 0.001), 
          notes        = "*p<0.05; **p<0.01; ***p<0.001", 
          notes.append = FALSE, no.space = TRUE,
          out="mod.htm")




## ROBUSTNESS CHECK

## EXCLUDE IRELAND AND ARGENTINA

# Do same exact analysis as above, but exclude Ireland and Argentina 

rm(list=ls(all=TRUE))
detach(MPs.replies)


## Subset: exclude Ireland and Argentina

MPs.replies <- read.csv("C:/Users/gmagni/OneDrive/SideProjects/1-Zoi/0000-JEPS/Dataset/merged-updated-Rnames-dates-final-jeps.csv")
MPs.replies <- subset(MPs.replies, country != "Ireland" & country != "Argentina")
attach(MPs.replies)


## Code variables 


#Re-code treatment: Name: "treat.female":  female sender = 1; male sender = 0
table(treat)
treat.female <- as.numeric(treat=="F")
table(treat.female)

table(MPs.replies$treat)
treat.female <- as.numeric(MPs.replies$treat=="F")
table(treat.female)
MPs.replies$treat.female <- treat.female


table(treat)
treat.female <- as.numeric(treat=="F")
table(treat.female)

#Recode age (which is a factor) into a numeric variable
age2 <- as.character(age)
age2 <- as.numeric(age2)
table(age2)

#Recode ideology (which is a factor) into a numeric variable
party.gen.ideo2 <- as.character(party.gen.ideo)
party.gen.ideo2 <- as.numeric(party.gen.ideo2)
table(party.gen.ideo2)

#Recode economic ideology (which is a factor) into a numeric variable
table(party.eco.ideo)
party.eco.ideo2 <- as.character(party.eco.ideo)
party.eco.ideo2 <- as.numeric(party.eco.ideo2)
table(party.eco.ideo2)

#Recode social ideology (which is a factor) into a numeric variable
table(party.soc.ideo)
party.soc.ideo2 <- as.character(party.soc.ideo)
party.soc.ideo2 <- as.numeric(party.soc.ideo2)
table(party.soc.ideo2)

#Create country dummies
table(country)
ireland <- as.numeric(country=="Ireland")
italy <- as.numeric(country=="Italy")
france <- as.numeric(country=="France")
germany <- as.numeric(country=="Germany")
netherlands <- as.numeric(country=="Netherlands")
argentina <- as.numeric(country=="Argentina")
brazil <- as.numeric(country=="Brazil")
chile <- as.numeric(country=="Chile")
colombia <- as.numeric(country=="Colombia")
mexico <- as.numeric(country=="Mexico")
uruguay <- as.numeric(country=="Uruguay")




## ANALYSIS


# APPENDIX TABLE A6 

# MPs' responsiveness to citizens' demands ("real responses," excluding Ireland and Argentina)
# Multilevel (random intercept)

multil.treat <- glmer(real.resp.1 ~ treat.female + (1 | country), 
                      family=binomial(link="logit"))
summary(multil.treat)


multil.general <- glmer(real.resp.1 ~ treat.female + female + age2 + (1 | country), 
                        family=binomial(link="logit"))
summary(multil.general)


multi.all.dates <- glmer(real.resp.1 ~ treat.female + female + age2 + party.gen.ideo2 + gov.coal +
                           es.prefer + female.mps + post.days +
                           (1| country), 
                         family=binomial(link="logit"))
summary(multi.all.dates)


stargazer(multil.treat, multil.general, multi.all.dates, type="html", digits = 2,
          star.char = c("*", "**", "***"), 
          star.cutoffs = c(0.05, 0.01, 0.001), 
          notes        = "*p<0.05; **p<0.01; ***p<0.001", 
          notes.append = FALSE, no.space = TRUE,
          out="mod.htm")




# APPENDIX TABLE A7

# MPs' responsiveness to citizens' demands (all responses, excluding Ireland and Argentina)
#Multilevel (random intercept) 

multil.treat.allresp <- glmer(resp.1 ~ treat.female + (1 | country), 
                              family=binomial(link="logit"))
summary(multil.treat.allresp)


multil.general.allresp <- glmer(resp.1 ~ treat.female + female + age2 + (1 | country), 
                                family=binomial(link="logit"))
summary(multil.general.allresp)


multi.all.dates.allresp <- glmer(resp.1 ~ treat.female + female + age2 + party.gen.ideo2 + gov.coal +
                                   es.prefer + female.mps + post.days +
                                   (1| country), 
                                 family=binomial(link="logit"))
summary(multi.all.dates.allresp)


stargazer(multil.treat.allresp, multil.general.allresp, multi.all.dates.allresp, 
          type="html", digits = 2,
          star.char = c("*", "**", "***"), 
          star.cutoffs = c(0.05, 0.01, 0.001), 
          notes        = "*p<0.05; **p<0.01; ***p<0.001", 
          notes.append = FALSE, no.space = TRUE,
          out="mod.htm")
